package com.op.parcel.manage.config.security.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.op.parcel.common.api.R;
import com.op.parcel.common.constant.CommonConstant;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author xuan🐽
 */
@Slf4j
public class HttpDataUtil {

	public static void respJson(HttpServletResponse response, R r) {
		PrintWriter out = null;
		try {
			response.setContentType(CommonConstant.CONTENT_TYPE_JSON);
			out = response.getWriter();
			out.println(new ObjectMapper().writeValueAsString(r));
		} catch (Exception e) {
			log.error(e + "输出JSON出错");
		} finally {
			if (out != null) {
				out.flush();
				out.close();
			}
		}
	}
}
